package com.jieyang.oa.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.jieyang.oa.dao.IncomeDao;
import com.jieyang.oa.pojo.Vo.IncomeListVo;
import com.jieyang.oa.pojo.entity.Income;
import com.jieyang.oa.service.IncomeService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author 29276
 * @version 1.0
 * @description: TODO
 * @date 2021/8/23 22:14
 */
@Service
@Transactional
public class IncomeServiceImpl implements IncomeService {

    @Resource
    private IncomeDao incomeDao;

    @Override
    public Integer insert(Income income) {
        return incomeDao.insert(income);
    }

    @Override
    public List<Income> selectIncomeTypeList() {
        return incomeDao.selectIncomeTypeList();
    }

    @Override
    public PageInfo<IncomeListVo> selectAll(int pageNum, int pageSize, String startDate, String endDate, String incomeType) {
        PageHelper.startPage(pageNum, pageSize);
        List<IncomeListVo> incomeListVos = incomeDao.selectAll(startDate, endDate, incomeType);

        PageInfo<IncomeListVo> incomeListVoPageInfo = new PageInfo<>(incomeListVos);
        int ceil = (int) Math.ceil((incomeDao.count(startDate, endDate, incomeType)*1.0)/pageSize);
        incomeListVoPageInfo.setPages(ceil);
        incomeListVoPageInfo.setSize(incomeDao.count(startDate, endDate, incomeType));

        return incomeListVoPageInfo;
    }

    @Override
    public Integer delete(Long incomeId) {
        return incomeDao.delete(incomeId);
    }

    @Override
    public IncomeListVo selectByIncomeId(Long incomeId) {
        return incomeDao.selectByIncomeId(incomeId);
    }
}
